using System.Collections.Generic;
using HRC.Library.DBAccessLayer.Parameters;
using HRC.Library.EntityLibrary.EntityOperations;
using Lehnet.Models;
using Lehnet.BusinessLayer.Interfaces;
using HRC.Library.ContextFoundation;

namespace Lehnet.BusinessLayer
{
    public class IlceBusiness : IIlceBusiness
    {
        public void SaveOrUpdate(Models.Ilce ilce)
        {
            if (ilce.Id == 0)
                EntityManager.Insert(ilce);
            else
            {
                ilce = EntitySessionManager.Instance.GetOldEntity<Models.Ilce>(ilce);
                ProxyHelper<IlceBusiness, IIlceBusiness>.Instance.AddOrGet().Update(ilce);
            }
        }

        public List<Models.Ilce> LoadAll(int SehirId)
        {
            return EntityManager.LoadAll<Models.Ilce>(" where IlId=" + SehirId);
        }

        public Models.Ilce GetIlceById(int Id)
        {
            return EntityManager.Load<Models.Ilce>(" where Id=" + Id);
        }

        public void Delete(int ilceId)
        {
            EntityManager.Delete<Models.Ilce>(new HRCParameter("Id", ilceId, HRCParameterType.INT));
        }

        public List<Ilce> GetIlcelerByIlId(int ilId)
        {
            return EntityManager.LoadAll<Models.Ilce>(new HRCParameter("IlId", ilId, HRCParameterType.INT));
        }


        public void Update(Ilce ilce)
        {
            EntityManager.Update(ilce);
        }
    }
}
